<template>
  <div class="infinite-container">
    <div class="lefttime">
      状态：{{pageData.consultStatus | filterMedicalStatus}}
      <template v-if="pageData.consultStatus === 10">
            <span v-if="pageData.leftTimeTxt!=='已超时'">
              (剩余时间{{pageData.leftTimeTxt}})
            </span>
        <span v-else>
              (已超时)
            </span>
      </template>
    </div>

    <div class="contentBox">
      <div class="fcon">
        <div class="flex flex_between">
          <span>订单时间</span>
          <span>{{pageData.createTime}}</span>
        </div>
        <div class="item-con">
          <div>
            <div class="item-con-mid">
              <div>
                <img src="../../assets/wzjl/icon_zxwz_doctor.png">
              </div>
              <div>
                <h3><span>{{pageData.doctName}}</span><span>{{pageData.deptName}}</span></h3>
                <div><img src="../../assets/wzhis/icon_yao.png"><span>复诊配药</span></div>
              </div>
              <div>
                <span>￥{{pageData.cost}}</span>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="mt10"></div>
      <div class="bgwhite">
        <mu-list>
          <mu-list-item title=" 问诊人">
            <span slot="right" class="feeText">{{pageData.personName}} {{pageData.gender | getSex}} {{pageData.age}}岁</span>
          </mu-list-item>
          <mu-divider/>
          <mu-list-item title=" 上次就诊">
            <div slot="right" class="text-right">
              <p>{{pageData.visitTime}}</p>
              <p>{{pageData.orgName}} / {{pageData.preDeptName}}</p>
            </div>
          </mu-list-item>
          <mu-divider/>
          <mu-list-item title=" 确诊诊断">
            <div slot="right" class="longText flex flex_right">
              <span>{{pageData.diagnosis}}</span>
            </div>
          </mu-list-item>
          <mu-divider/>
          <mu-list-item title=" 所需药品">
            <div slot="right">
              <span class="drugBtn">{{pageData.drugs}}</span>
            </div>
          </mu-list-item>
        </mu-list>
      </div>
      <div class="mt10"></div>
      <left-border-title :title="'病情描述'">
      </left-border-title>
      <div class="scon bgwhite">
        {{pageData.question}}
      </div>
      <div class="mt10"></div>
      <left-border-title :title="'病情照片'"></left-border-title>
      <ul class="fileHandler flex wrap bgwhite" v-if="pageData.attrs.length > 0">
        <li v-for="(img, i) in pageData.attrs" :key="i"><a :href="img.fileUrl"><img v-lazy="img.fileUrl" alt=""></a></li>
      </ul>
      <div v-else class="pd10 bgwhite t3">没有图片</div>
    </div>
<!--未超时，可支付也可以取消的状态-->
    <div class="lcon flex" v-show="pageData.consultStatus == 10 && pageData.leftTimeTxt != '已超时'">
      <mu-raised-button label="取消问诊" fullWidth @click="goCancel()" style="height: 100%;width: 50%;"></mu-raised-button>
      <mu-raised-button label="去支付" fullWidth primary @click="gotoPay" style="height: 100%;width: 50%;"></mu-raised-button>
    </div>
<!--已退款，已超时-->
    <div class="lcon" v-show="pageData.consultStatus == 12 || pageData.consultStatus == 13 || pageData.consultStatus == 14">
      <mu-raised-button label="再次咨询" fullWidth primary @click="goMedicalQueryAgain()" style="height: 100%;"></mu-raised-button>
    </div>
    <mu-dialog :open="confirmCancel">
      <div class="center">是否取消订单？</div>
      <div class="center mt20" >
        <mu-flat-button slot="actions" @click="confirmCancel=false" label="否" />
        <mu-flat-button slot="actions" primary @click="cancelOrder" label="是" />
      </div>
    </mu-dialog>
  </div>
</template>

<script>
  import leftBorderTitle from "../../components/leftBorderTitle.vue";
  import TimeCounter from "../../components/TimeCounter.js";
  import {commonAjaxJson, RESTFUL_API} from '../../api/api'
  // 页面功能：复诊配药的详情页，功能为再次支付，取消问诊，再次咨询
  export default {
    data() {
      return {
        pageData: {attrs:[]},
        timeCounter: null,
        confirmCancel: false
      };
    },
    components: {
      leftBorderTitle
    },
    methods: {
      getConsultDetails(id) {
        commonAjaxJson(RESTFUL_API.getConsultDetails, {consultId: id})
          .then(res => {
            if (res.data.code == 200) {
              this.pageData = res.data.data;
              if (!res.data.payRemainingSeconds) {
                return
              }
              res.data.data.leftTimeTxt = "-:-";
              if (!this.timeCounter) {
                this.timeCounter = new TimeCounter(30 * 60);
              }
              this.timeCounter.ready().then(() => {
                if (this.timeCounter.checkIsTimeOut(res.data.data.payRemainingSeconds)) {
                  res.data.data.leftTimeTxt = "已超时";
                }
              });
              this.timeCounter.timeChangCallback = splash => {
                var txt = this.timeCounter.calTime(res.data.data.payRemainingSeconds, splash);
                res.data.data.leftTimeTxt = txt;
              };
              this.timeCounter.start();
            }
          });
      },
      goMedicalQueryAgain () {
        this.$router.replace({
          path: '/queryOnline/doctorDetail',
          query: {
            docid: this.pageData.doctId
          }
        })
      },
      goCancel() {
        if(this.pageData.consultStatus === 10) {
          this.confirmCancel = true
        } else {
          this.$router.push({
            path: '/queryHistory/cancelReason',
            query: {
              cid: this.pageData.consultId,
              action: 'medicalAgainCancel'
            }
          })
        }
      },
      cancelOrder() {
        
        this.confirmCancel = false
        let param = {
          consultId: this.pageData.consultId
        };
        commonAjaxJson(RESTFUL_API.cancelDispenseOrder, param, true)
          .then(res => {
            
            if (res.data.code == 200) {
              this.$store.commit("UPDATE_TOAST", {
                message:"取消成功",
                fn: () => {
                  this.getConsultDetails(this.$route.query.id);
                }
              });
            } else {
              this.$store.commit("UPDATE_TOAST", {
                message: res.data.message
              });
            }
          })
          .catch(res => {
            
          });
      },
      gotoPay() {
        this.$router.push({
          path: "/medicalAgain/confirmPay",
          query: {
            cid: this.pageData.consultId
          }
        });
      }
    },
    mounted() {
      let id = this.$route.query.id;
      if (!id) {
        return;
      }
      this.getConsultDetails(id);
    }
  };
</script>

<style lang="less" scoped>
  @import "../../common/css/flex.css";
  @import "../../common/css/component";

  .infinite-container {
    padding-bottom: 30px;
    @{deep} .mu-item-left img {
      width: 30px;
      height: 30px;
    }
    @{deep} .mu-item.show-left {
      padding-left: 60px;
    }
    @{deep} .mu-item-title {
      color: #333;
      font-size: 14px;
    }
    @{deep} .mu-item-text {
      color: #ccc;
    }
    @{deep} .mu-item {
      min-height: 44px;
      height: 44px;
    }
    .feeText {
      color: #0fc47d;
      font-size: 14px;
      font-weight: 400;
    }
    .lefttime {
      width: 100%;
      height: 35px;
      line-height: 35px;
      text-align: center;
      font-size: 14px;
      color: #ff6600;
      background: #fffdce;
      border-bottom: 1px solid #e8e8e8;
    }
    .item-con {
      background: #fff;
      padding: 15px 0 15px 0px;
      > div {
        width: 100%;
        position: relative;
      }
      &-mid {
        display: table;
        width: 100%;
        > div:first-child {
          display: table-cell;
          vertical-align: middle;
          width: 52px;
          > img {
            width: 52px;
            height: 52px;
            vertical-align: middle;
          }
        }
        > div:nth-child(2) {
          display: table-cell;
          padding-left: 15px;
          vertical-align: middle;
          > h3 {
            font-size: 16px;
            color: #333;
            font-weight: normal;
            font-size: 14px;
            padding-bottom: 2px;
            > span:first-child {
              font-size: 16px;
              padding-right: 10px;
            }
            > span:last-child {
              color: #666;
            }
          }
          > div {
            font-size: 14px;
          }
          > div:first-of-type {
            display: flex;
            align-items: center;
            > img {
              width: 15px;
              margin-right: 10px;
            }
            color: #999;
          }
        }
        > div:last-child {
          vertical-align: middle;
          display: table-cell;
          width: 1%;
          white-space: nowrap;
          font-size: 20px;
          color: #ff6600;
          text-align: right;
        }
      }
    }
    .fcon {
      padding: 0px 15px 0px 15px;
      background: #fff;
      border-bottom: 1px solid #e8e8e8;
      > div:first-child {
        width: 100%;
        height: 40px;
        line-height: 40px;
        border-bottom: 1px solid #e8e8e8;
        font-size: 14px;
        color: #666;
      }
    }
    .scon {
      border-top: 1px solid #e8e8e8;
      width: 100%;
      padding: 15px;
      color: #666;
      font-size: 14px;
    }
    .tcon {
      border-top: 1px solid #e8e8e8;
      width: 100%;
      padding: 15px;
      color: #666;
      font-size: 14px;
    }
    .fileHandler {
      border-top: 1px solid #e8e8e8;
      padding: 0px 15px;
      padding-bottom: 20px;
      li {
        position: relative;
        width: 25%;
        height: 25%;
        display: flex;
        align-items: center;
        justify-content: center;
        margin-top: 20px;
        img {
          width: 80%;
          height: 80%;
          border-radius: 4px;
        }
      }
    }
    .lcon {
      width: 100%;
      position: absolute;
      bottom: 0;
      height: 48px;
    }
  }
  .longText{
    >span{
      // max-width: 70%;
      word-break: break-all;
      text-align: right;
    }
  }
  .drugBtn{
    display: block;
    border-radius: 8px;
    padding: 3px 5px;
    border: 1px solid @color-primary;
    color: @color-primary;
    background-color: white;
  }
  .contentBox{
    width: 100%;
    left: 0;
    position: absolute;
    top: 35px;
    bottom: 50px;
    overflow-y: scroll;
  }
</style>
